from django.db import models
from apps.common.base.models import BaseModel
from apps.system.payway.models import Payway
from  apps.system.user.models import User
from apps.merchant.shop.models import Shop

class RecordIncomes(BaseModel):
    '''积分收支记录'''
    payway = (
        ('wxpay', "微信"),
        ('alipay', "支付宝"),
        ('incomeAndIncomeLocked', "积分组合支付"),
        ('incomes', "购物积分"),
        ('incomesLocked', "锁仓补贴"),
        ('balance', "现金余额"),
        ('contributionValue', "贡献值"),
        ('incomesCredit', "抵扣积分"),
        ('incomesOriginal', "原积分"),
        ('incomesReduction', "立减积分"),
        ('cashSellingMoney', '销售额结余'),
        ('freePoolDay', '日释放池'),
        ('freePoolMonth', '月释放池'),
        ('supplyAwards', '供应链奖励'),
        ('helpFundPool', '创业基金池'),
        ('grossProfit', '毛利润'),
        ('operationAwardPool', '运营补贴'),
        ('shop_balance', '结算金额')
    )
    scene = (
        ('expense', "消费"),
        ('unlockedIncomes', "锁仓积分释放"),
        ('verticalAward', '直推奖励'),
        ('gradeAward', "见点奖"),
        ('incomes', "收益"),
        ('stockCart', '采购'),
        ('agentIncomes', '代理商收益'),
        ('outMoney', '提现'),
        ('inMoney', '充值'),
        ('outMoneyForRefuse', '提现拒绝返还'),
        ('expenseReturn', '退款返还'),
        ('addIncomeFromAdmin', "管理员充值"),
        ('subIncomeFromAdmin', "管理员扣除"),
        ('subToBalance', '转余额扣除'),
        ('incomesToBalance', '积分转余额'),
        ('sendForExpense', '消费赠送'),
        ('teamAward', '团队奖励'),
        ('levelAward', '团队平级奖励'),
        ('lockedFree', '锁仓释放'),
        ('fromOriginal', '原积分转换'),
        ('freeForMonth', '月释放'),
        ('verticalShopAward', '商户推荐人奖励'),
        ('onlineSettle', '线上支付结算'),
        ('shopinSettle', '店内支付结算'),
    )
    orderStatus = (
        ("INITIAL", "初始状态"),
        ('WAIT_SEND', "待发送"),
        ('FINISH', "完成"),
        ("REFUSE", "已拒绝"),
    )
    scene = models.CharField("钱包收支类型", max_length=100, choices=scene, blank=True, null=True)
    shop = models.ForeignKey(Shop, related_name="shop_recordIncomes", verbose_name='商户', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    user = models.ForeignKey(User, related_name='recordIncomes_set', verbose_name='用户', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    fromUser=models.ForeignKey(User, related_name='recordIncomes_from_set', verbose_name='来自用户', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    payWayAccount = models.ForeignKey(Payway, related_name='payWayAccount_recordIncomes', verbose_name='收款账户', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    receiptAccount = models.CharField('收款信息', max_length=500, blank=True, default='')
    orderId = models.CharField('订单ID', max_length=100, blank=True)
    money=models.DecimalField("金额",max_digits=20, decimal_places=2, default=0)
    moneyLocked = models.DecimalField("锁仓金额", max_digits=20, decimal_places=2, default=0)
    balanceIncomes = models.DecimalField("余额积分", max_digits=20, decimal_places=2, default=0)
    serviceCharge=models.DecimalField("服务费",max_digits=10, decimal_places=2, default=0)
    realMoney=models.DecimalField("实际到账",max_digits=20, decimal_places=2, default=0)
    outMoneyTime = models.DateTimeField('处理日期', null=True, blank=True)
    payway=models.CharField("付款类型", choices=payway, max_length=100, blank=True, null=True)
    changeWay = models.CharField("变动方向", max_length=200, blank=True, null=True, default='') #增加/减少
    orderStatus = models.CharField("记录状态", max_length=100, choices=orderStatus, default="INITIAL")
    freeRecord = models.CharField('释放记录', max_length=10000, blank=True, default='')
    remark = models.CharField('备注', max_length=200, blank=True, default='')

    class Meta:
        verbose_name = '钱包记录'
        verbose_name_plural = verbose_name